<template>
    <Form
            ref="form"
            :form-items="formItems"
    ></Form>
</template>

<script>
    import Form from '../../../../../../common-util/src/components/page/Form.vue'
    export default {
        components:{
            Form
        },
        data(){
            return {
                appCode: this.$route.query.appCode,
                type: this.$route.query.type,
                formItems:[
                    {
                        field: {
                            name: 'file'
                        },
                        element:{
                            type: 'upload',
                            upload:{
                                type: 'upload',
                                limit: 1,
                                showFileList: true,
                                listType: 'text',
                                multiple: false,
                                autoUpload: false
                            },
                            required: true,
                            label: '媒体',
                            tips: '图片（image）: 10M，支持bmp/png/jpeg/jpg/gif格式\n' +
                                '<br/>' +
                                '语音（voice）：2M，播放长度不超过60s，mp3/wma/wav/amr格式\n' +
                                '<br/>' +
                                '视频（video）：10MB，支持MP4格式\n' +
                                '<br/>' +
                                '缩略图（thumb）：64KB，支持JPG格式'
                        }
                    },
                    {
                        field: {
                            name: 'title'
                        },
                        element:{
                            label: '标题',
                            placeholder: '视频素材的标题',
                            required: true,
                            show: ()=>{return this.type == 'video'}
                        }
                    },
                    {
                        field: {
                            name: 'introduction'
                        },
                        element:{
                            label: '描述',
                            placeholder: '视频素材的描述',
                            required: true,
                            show: ()=>{return this.type == 'video'}
                        }
                    },

                    {
                        element:{
                            type: 'button',
                            button:[
                                {
                                    action: 'submit',
                                    requestMethod:'post',
                                    requestType: 'multipart',
                                    url: this.addUrl,
                                    label: '保存'
                                },
                                {
                                    action: 'reset',
                                    label: '重置',
                                    type: 'default'
                                }
                            ]
                        }
                    }
                ]
            }
        },
        mounted(){
            if(!this.appCode){
                this.$message.error('参数错误，缺少公众号编码appCode')
            }
            if(!this.type){
                this.$message.error('参数错误，缺少媒体类型type')
            }
        },
        methods:{
            addUrl() {
                if(!this.appCode || !this.type){
                    this.$message.error('参数错误，缺少公众号编码appCode或媒体类型type')
                    return false
                }
                return this.$baseURL.wx + '/wx/mp/material/'+ this.appCode +'/create/file/' + this.type
            },
        }
    }
</script>

<style scoped>

</style>